package com.example.demo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by vincent on 2018/5/10.
 */
@RestController
public class ConsumerController {
    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "fallBack")
    @GetMapping("helloConsumer")
    public String helloConsumer(){
        return restTemplate.getForEntity("http://compute-service/add?a={1}&b={2}", String.class, 5,6).getBody();
    }

    public String fallBack(){
        return "error";
    }
}
